package com.zxy.ziems.server.energy.controller;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.zxy.btp.common.response.JsonResponse;
import com.zxy.btp.common.response.PageResult;
import com.zxy.btp.security.annotation.IgnoreLogin;
import com.zxy.btp.web.util.TokenUtils;
import com.zxy.ziems.server.energy.pojo.param.DeviceMeasureDataDay;
import com.zxy.ziems.server.energy.pojo.param.DeviceMeasureDataDayPageParam;
import com.zxy.ziems.server.energy.pojo.param.DeviceMeasureDataIncrementHour;
import com.zxy.ziems.server.energy.pojo.param.DeviceMeasureDataIncrementHourPageParam;
import com.zxy.ziems.server.energy.pojo.vo.DeviceMeasureDataDayVO;
import com.zxy.ziems.server.energy.pojo.vo.DeviceMeasureDataIncrementHourVO;
import com.zxy.ziems.server.energy.service.DeviceMeasureDataDayService;
import com.zxy.ziems.server.energy.service.DeviceMeasureDataIncrementHourService;
import com.zxy.ziems.server.utils.DateUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Objects;


@RestController
@RequiredArgsConstructor
@CrossOrigin
@RequestMapping("/api/deviceMeasure")
public class DeviceMeasureDataController {

    @Autowired
    private DeviceMeasureDataDayService deviceMeasureDataDayService;
    @Autowired
    private DeviceMeasureDataIncrementHourService deviceMeasureDataIncrementHourService;


    @GetMapping("/day/page")
    public PageResult<DeviceMeasureDataDayVO> getDayPageList(DeviceMeasureDataDayPageParam param) {

        return deviceMeasureDataDayService.getPageList(param);
    }


    @PostMapping("/day/update")
    public JsonResponse<String> updateMeasureDayData(@RequestBody DeviceMeasureDataDay data) {

        boolean result = deviceMeasureDataDayService.updateMeasureDayData(data);

        return result ? JsonResponse.SUCCESS("更新成功") : JsonResponse.ERROR("数据已被修改，请刷新后重试");
    }


    @GetMapping("/incrementHour/page")
    public PageResult<DeviceMeasureDataIncrementHourVO> getIncrementHourPageList(DeviceMeasureDataIncrementHourPageParam param) {

        return deviceMeasureDataIncrementHourService.getPageList(param);
    }


    @PostMapping("/incrementHour/update")
    public JsonResponse<String> updateMeasureIncrementHourData(@RequestBody DeviceMeasureDataIncrementHour data) {

        boolean result = deviceMeasureDataIncrementHourService.updateMeasureIncrementHourData(data);

        return result ? JsonResponse.SUCCESS("更新成功") : JsonResponse.ERROR("数据已被修改，请刷新后重试");
    }
}
